{extend name="base" /} {block name="body"}
<div class="admin-main">
    <div class="layui-field-box layui-form">

        <table class="layui-table admin-table">
            <thead>
            <tr>
                <th width="5%" style="text-align: center">ID</th>
                <th width="20%" style="text-align: center">广告位</th>
                <th width="10%" style="text-align: center">一行显示的列数</th>
                <th width="10%" style="text-align: center">行高</th>
                <th width="20%" style="text-align: center">手机版显示</th>
                <th width="20%" style="text-align: center">总开关</th>
                <th width="15%" style="text-align: center">操作</th>
            </tr>
            </thead>
            <tbody>
            {volist name="list" id="vo"}
            <tr>
                <td align="center">{$vo.id}</td>
                <td align="center">{$vo.title}</td>
                <td align="center">{$vo.columns}</td>
                <td align="center">{$vo.rows}</td>
                <td align="center">
                    <input type="checkbox"  data-column="mobile_open" lay-skin="switch" lay-text="开启|关闭" lay-filter="switchSet" value="{$vo.id}" {php}echo $vo[ 'mobile_open']==1 ? 'checked' : '';{/php}>
                </td>
                <td align="center">
                    <input type="checkbox" data-column="status" lay-skin="switch" lay-text="开启|关闭" lay-filter="switchSet" value="{$vo.id}" {php}echo $vo[ 'status']==1 ? 'checked' : '';{/php}>
                </td>
                <td align="center">
                    <a class="layui-btn layui-btn-normal layui-btn-sm cate-edit" data-id="{$vo.id}" data-name="{$vo.columns}"
                       href="javascript:;">修改列数</a>
                    <a class="layui-btn layui-btn-normal layui-btn-sm cate-edit2" data-id="{$vo.id}" data-name="{$vo.rows}"
                       href="javascript:;">修改行高</a>
                </td>
            </tr>
            {/volist}
            </tbody>
        </table>
    </div>


</div>
{/block} {block name="js"}
<script type="text/javascript" src="__ADMIN__/js/delelement.js"></script>
{/block} {block name="script"}
<script>
    layui.use(['form'], function () {
        var form = layui.form,
            jq = layui.jquery;


        var accept_ls_push = 0;
        form.on('switch(switchSet)', function(data) {
            loading = layer.load(2, {
                shade: [0.2, '#000']
            });
            var column=jq(this).data('column');
            if (data.elem.checked) {
                status = 1;
            } else {
                status = 0;
            }
            var url = "{:url('admin/AdCategory/toggle')}?id=" + data.value + '&status=' + status + '&name='+column;
            jq.get(url, function (data) {

                if (data.code == 200) {
                    layer.close(loading);
                    layer.msg(data.msg, {
                        icon: 1,
                        time: 1000
                    });
                } else {
                    layer.close(loading);
                    layer.msg(data.msg, {
                        icon: 2,
                        anim: 6,
                        time: 1000
                    });
                }
            });
            return false;
        });

        jq('.cate-edit').on('click', function (data) {

            var id=jq(this).data('id');
            var name=jq(this).data('name');
            var url = "{:url('admin/adCategory/update')}?id=" + id;
            layer.prompt({title: '修改列数(只能填写1,2,3,4,6,12)',value:name}, function(text, index){
                jq.post(url, {columns:text},function (res) {

                    if (res.code == 200) {

                        layer.msg(res.msg, {
                            icon: 1,
                            time: 1000
                        },function () {
                            location.reload();
                        });
                    } else {

                        layer.msg(res.msg, {
                            icon: 2,
                            anim: 6,
                            time: 1000
                        });
                    }
                });
            });
            return false;
        });

        jq('.cate-edit2').on('click', function (data) {

            var id=jq(this).data('id');
            var name=jq(this).data('name');
            var url = "{:url('admin/adCategory/update')}?id=" + id;
            layer.prompt({title: '修改广告高度（单位px，最小75）',value:name}, function(text, index){
                jq.post(url, {rows:text},function (res) {

                    if (res.code == 200) {

                        layer.msg(res.msg, {
                            icon: 1,
                            time: 1000
                        },function () {
                            location.reload();
                        });
                    } else {

                        layer.msg(res.msg, {
                            icon: 2,
                            anim: 6,
                            time: 1000
                        });
                    }
                });
            });
            return false;
        });
    })
</script>
{/block}